package com.ffms.servlet; /**
 * @author 从卿
 * @create 2022/3/10-23:59
 */

import com.ffms.dao.ShouruDao;
import com.ffms.dao.impl.ShouruDaoImpl;
import com.ffms.dao.impl.ZhiChuDaoImpl;
import com.ffms.entity.Shouru;
import com.ffms.entity.ZhiChu;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/AddZhiChuServlet")
public class AddZhiChuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);}

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        //1.接收视图层传来的表单数据并封装完成对象
        String why = request.getParameter("why");
        String money = request.getParameter("money");
        Date date=Date.valueOf(request.getParameter("date"));
        String way = request.getParameter("way");
        int mssid= Integer.parseInt(request.getParameter("mzsid"));
        ZhiChu zhiChu = new ZhiChu(why,money,date,way,mssid);
        //2
       ZhiChuDaoImpl zhiChuDao=new ZhiChuDaoImpl();
        int n = zhiChuDao.addZhichu(zhiChu);


        //根据结果跳转到不同的页面
        if (n > 0) {

            response.sendRedirect(request.getContextPath() + "/AllZhiChuServlet");

        } else {
            request.setAttribute("error1", "添加账户失败");
            request.getRequestDispatcher("/admin/zhichuAdd.jsp").forward(request, response);
        }
    }
}
